﻿using AutoMapper;
using MediatR;
using S.Archives.Api.Application.Command;
using S.Archives.Domain.S.ArchivesModel;
using S.Archives.Infrstructre.InterFace;


namespace S.Archives.Api.Application.CommandHandlers
{
    public class SheepFileCreateCommandHandler : IRequestHandler<SheepFileCreateCommand, bool>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public SheepFileCreateCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 档案新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(SheepFileCreateCommand request, CancellationToken cancellationToken)
        {
            //创建人通过权限获取
            
            request.CreateDate = DateTime.Now;
            request.UpdateBy = "";
            request.UpdateDate = null;

            SheepFileModel sheepFileModel = mapper.Map<SheepFileModel>(request);
            return await sheepFileRepository.AddAsync(sheepFileModel);
        }
    }
}
